package com.minigame.chess.gobang.controller;

import com.minigame.chess.gobang.entity.request.JudgeRequest;
import com.minigame.common.ApiResponse;
import com.minigame.chess.gobang.service.ChessService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ChessController {

    @Resource
    private ChessService chessService;

    @RequestMapping("/register")
    public ApiResponse<Void> register(@RequestParam String name) {
        chessService.savePlayer(name);
        return new ApiResponse<>();
    }

    @RequestMapping("/start")
    public ApiResponse<Void> start(@RequestParam Integer[] players) {
        chessService.saveRound(players);
        return new ApiResponse<>();
    }
    @RequestMapping("/put")
    public ApiResponse<Boolean> judge(@RequestBody JudgeRequest judgeRequest) {
        return new ApiResponse<>(chessService.putAndWin(judgeRequest));
    }
}
